package com.keeping.aiimagery.service.impl;

import com.keeping.aiimagery.entity.OrdersServices;
import com.keeping.aiimagery.entity.Services;
import com.keeping.aiimagery.entity.User;
import com.keeping.aiimagery.entity.QueryVo;
import com.keeping.aiimagery.mapper.OrdersServicesMapper;
import com.keeping.aiimagery.mapper.ServicesMapper;
import com.keeping.aiimagery.mapper.UserMapper;
import com.keeping.aiimagery.service.OrdersServicesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 消费记录 服务实现类
 * </p>
 *
 * @author keeping
 * @since 2023-04-05
 */
@Service
public class OrdersServicesServiceImpl extends ServiceImpl<OrdersServicesMapper, OrdersServices> implements OrdersServicesService {

    @Resource
    private OrdersServicesMapper ordersServicesService;
    @Resource
    private UserMapper userMapper;
    @Resource
    private ServicesMapper servicesMapper;

    @Override
    public Boolean cut(String userAccount,Integer integral,String name){
        User user = userMapper.login(userAccount);
        Services services = servicesMapper.findByName(name);
        if(user.getIntegral()<integral){
            ordersServicesService.cut(user.getId(),integral,name,services.getId(),"失败" );
            return false;
        }else {
            ordersServicesService.cut(user.getId(),integral,name,services.getId(),"完成" );
            userMapper.cut(user.getId(),integral);
            return true;
        }


    }
    public List<OrdersServices> selectByPage(QueryVo queryVo){
        return ordersServicesService.selectByPage(queryVo);
    }
    public int coutById(Integer userId){
        return ordersServicesService.coutById(userId);
    }
}
